<template>
	<view class="set">
		<view class="item" @tap="update">
			<view ><text>修改密码</text></view>
			<view><image mode="widthFix" src="../../../static/images/icon/you.png"></image></view>
		</view>
		<view class="item" @click="toupdate()" >
			<view ><text>当前版本</text></view>
			<view class="grey"><span v-if="flag" style="color: red; padding-right: 10px;">有新版本</span>V{{version}}</view>
		</view>
		<view class="bottom" @tap="logout">
			退出登录
		</view>
	</view>
</template>

<script>
	var _this;
	import { mapState } from 'vuex';
	import {MQTTconnect,closeConnect} from "@/socket.js";
		export default {
		data() {
			return {
				version:'',
				flag:false
			}
		},
		onLoad() {
			_this = this;
				// #ifdef APP-PLUS
			this.version = this.$version;
			var oldversion = this.$version;
			let isIos = plus.os.name === 'iOS' ? 1 : 0;
			
			var phone = null;
			if (isIos) {
				phone = 'ios';
			} else {
				phone = 'android';
			}
			uni.request({
				url: 'http://mobile.suxin88.com:808/version.json?' + Math.random() * 10,
				success: res => {
					console.log(res.data[phone].version);
					if (res.data[phone].version != oldversion) {
						this.flag = true;
					}
				
				},
				fail: err => {
					console.log(err);
				}
			});
			// #endif
			
		},
		methods: {
			toupdate(){
				if(this.flag == true){
					var data={
						token: uni.getStorageSync('token')
					}
					this.$store.dispatch("logout",data)
					.then(res => {
						
						console.log(res)
						if(res.data.code==0){
							uni.showToast({
								title: res.data.msg,
								icon: 'none'
							});
						}
						else{
							_this.$store.commit("userinfo","")
							console.log("666")
							// #ifdef APP-PLUS
							this.stopaudio();
							// #endif
						}
					})
					_this.$bus.$emit("cleartimer",1)
					_this.$bus.$emit("cleartimern",1)
					_this.$bus.$emit("cleartimer1",1)
					uni.reLaunch({
						url: '../../login/login'
					});
					 closeConnect()
				}
			},
			update(){
				uni.navigateTo({
					url: '../../login/xiugaimima'
				});
			},
			logout(){
					uni.showModal({
						content: `确定退出登陆吗？`,
						success: function(res) {
							if (res.confirm) {
								uni.removeStorage({
								    key: 'password',
								    success: function (res) {
								        
								    }
								});
								var data={
									token: uni.getStorageSync('token')
								}
								_this.$store.dispatch("logout",data)
								.then(res => {
									
									console.log(res)
									if(res.data.code==0){
										uni.showToast({
											title: res.data.msg,
											icon: 'none'
										});
									}
									else{
										_this.$store.commit("userinfo","")
										console.log("666")
										// #ifdef APP-PLUS
										_this.stopaudio();
										// #endif
									}
								})
								_this.$bus.$emit("cleartimer",1)
								_this.$bus.$emit("cleartimern",1)
								_this.$bus.$emit("cleartimer1",1)
								uni.reLaunch({
									url: '../../login/login'
								});
								 closeConnect()
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
				
			}
			
			
			
		}
	};
</script>

<style lang="scss" scoped>
	.grey{
		color: #333;
	}
.set {
	min-height: calc(100vh - 40upx);
	// min-height: 100%;
	// background-color: #f4f4f4;
	padding-top: 30upx;
	.item {
		display: flex;
		justify-content: space-between;
		background-color: #fff;
		align-items: center;
		width: 612upx;
		height: 90upx;
		margin: 0 auto;
		border-bottom:  solid 2rpx #ececec;
		background-color: #ffffff;
		border-radius: 6upx;
		padding: 0 40upx;
		font-size: 32upx;
		view{
				font-size: 32upx;
		}
		label{
				font-size: 34upx;
			color: #c7c7c7;
		}
		image{
			width: 20rpx;
			height: 20rpx;
		}
	}
	.bottom{
		width: 562upx;
	height: 90upx;
	margin: 0 auto;
	line-height: 90upx;
	background-color: #2296f3;
	border-radius: 40rpx;
	color: #fff;
	text-align: center;
	position: fixed;
	font-size: 32upx;
	left: 0;
	right: 0;
	bottom: 64upx;
	}
}
</style>
